package com.salefinder.server.server.dao;

import java.util.List;

import org.hibernate.Session;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions;

import com.salefinder.server.server.exception.SystemException;
import com.salefinder.server.server.util.Constant;
import com.salefinder.server.server.vo.Brand;
import com.salefinder.server.server.vo.Merchant;

public class BrandDao extends BaseDao{

	
	public void createOrUpdateBrand(Brand vo){
		this.createOrUpdate(vo);
	}
	
	public void deleteBrand(Brand vo){
		this.delete(vo);
	}
	
	public void loadBrand(Brand vo){
		this.load(this.getClass(), vo.getId());
	}
	
	public List<Brand> searchConsumerBrandNames(String name, int limit) throws SystemException{
		List<Brand> list;
		
		try{
			Session session = this.getSessionFactory().openSession();
			
			list = session.createCriteria(Brand.class)
			.add(Restrictions.like("name", name +"%"))
			.addOrder(Order.asc("name"))
			.setMaxResults(Constant.MAX_SUGGESTION_RESULTS)
		    .list();
			session.close();

			}catch(Exception e){
				throw new SystemException(Constant.SYSTEM_ERROR,"System error creating user", e);
			}
			return list;
	}
}
